﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace PhysicsSimulator
{
    public partial class TurnableInputDataPage : PhoneApplicationPage
    {
        public TurnableInputDataPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

            Settings.TurnableRadial = float.Parse(TurnableRadial.Text);
            Settings.TurnableWeight = float.Parse(TurnableWeight.Text);
            Settings.TurnableVelocity = float.Parse(VelocityRadialPerSecond.Text);
            Settings.TurnableEnviromentRatio = (float)EnviromentRatio.Value;

            Settings.moment_save_active = true;
        }

        private void VelocityRadialPerSecond_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox textBox = sender as TextBox;
            if (textBox == null)
                return;
            if (String.Compare(textBox.Text, "") == 0)
            {
                textBox.Text = "0";
            }
            float value = float.Parse(textBox.Text);
            VelocityVongPerSecond.Text = (value / (2 * Math.PI)).ToString();
            VelocityVongPerMinute.Text = (value * 60 / (2 * Math.PI)).ToString();
        }

        private void VelocityVongPerMinute_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox textBox = sender as TextBox;
            if (textBox == null)
                return;
            if (String.Compare(textBox.Text, "") == 0)
            {
                textBox.Text = "0";
            }
            float value = float.Parse(textBox.Text);
            VelocityRadialPerSecond.Text = (value * 60 * (2 * Math.PI)).ToString();
            VelocityVongPerSecond.Text = (value * 60).ToString();
        }

        private void VelocityVongPerSecond_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox textBox = sender as TextBox;
            if (textBox == null)
                return;
            if (String.Compare(textBox.Text, "") == 0)
            {
                textBox.Text = "0";
            }
            float value = float.Parse(textBox.Text);
            VelocityRadialPerSecond.Text = (value * (2 * Math.PI)).ToString();
            VelocityVongPerMinute.Text = (value / 60).ToString();
        }
    }
}